<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            margin: 0;
            padding: 0;
        }
        #div1{
            width: 1000px;
            margin: auto;
            overflow: hidden;
            height: 200px;
            position: relative;

        }
        #div2{
            width: 1000px;
            margin:50px auto;
            text-align: center;
        }
        ul{
            margin: 0;
            padding: 0;
            list-style: none;
            font-size: 0;
            position: absolute;/*滚动一定是定位的元素*/
        }
        ul li{
            display: inline-block;
        }

    </style>
</head>
<body>
  <div id="div1">
      <ul>
          <li><img src="images/1.png" width="200" height="200"></li>
          <li><img src="images/2.png" width="200" height="200"></li>
          <li><img src="images/3.png" width="200" height="200"></li>
          <li><img src="images/4.png" width="200" height="200"></li>
          <li><img src="images/5.png" width="200" height="200"></li>
      </ul>
  </div>
  <div id="div2">
      <button id="btn1">向左走</button>
      <button id="btn2">向右走</button>
  </div>

  <script src="js/util.js" type="text/javascript"></script>
  <script type="text/javascript">
     var oDiv = document.getElementById('div1');
     var oUl = document.getElementsByTagName('ul')[0];
     var aLi = document.getElementsByTagName('li');
     var oBtn1 = document.getElementById('btn1');
     var oBtn2 = document.getElementById('btn2');

     var speed = -2;
     var timer = null;

     oUl.innerHTML += oUl.innerHTML;
     oUl.style.width = aLi[0].offsetWidth*aLi.length+'px';

     function moveWall() {
         if(oUl.offsetLeft<-oUl.offsetWidth/2){
             oUl.style.left = '0';
         }
         if(oUl.offsetLeft>0){
             oUl.style.left = -oUl.offsetWidth/2+'px';
         }

         oUl.style.left = oUl.offsetLeft+speed+'px';
     }

         timer = setInterval(moveWall,30);
         oBtn1.onclick = function () {
             speed = -2;
         };
         oBtn2.onclick = function () {
             speed = 2;
         };

     oUl.onmouseover = function () {
         clearInterval(timer);
     };
     oUl.onmouseout = function () {
         timer = setInterval(moveWall,30);
     }



















  </script>
</body>
</html>